package com.flexandair.controller
{
	import com.flexandair.model.ClassesProxy;
	import com.flexandair.view.CRUDdyBuddyMediator;
	import com.flexandair.view.ObjectDesignerCanvasMediator;
	import com.flexandair.view.components.ObjectDesignerCanvas;
	
	import org.puremvc.as3.interfaces.ICommand;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;

	public class AddDesignCanvasCommand extends SimpleCommand implements ICommand
	{
		public function AddDesignCanvasCommand()
		{
			super();
		}
		
		override public function execute(notification:INotification):void
		{
			//TODO: [NB]Perhaps a hack I will look in to it if necesary
			//For now the mediator just sits there. 
			//View component needs rewrite IMHO [NB]
			var random:int = Math.random() * 10000;
			while (facade.hasMediator(ObjectDesignerCanvasMediator.NAME + random.toString()) )
			{
				random = Math.random() * 10000;
			} 
			var viewComponent:ObjectDesignerCanvas = new ObjectDesignerCanvas();
			
			facade.registerMediator( new ObjectDesignerCanvasMediator( ObjectDesignerCanvasMediator.NAME , viewComponent ) );
			var cRUDdyBuddyMediator:CRUDdyBuddyMediator = facade.retrieveMediator( CRUDdyBuddyMediator.NAME) as CRUDdyBuddyMediator;

			//cRUDdyBuddyMediator.cruddyBuddy.designerHolder.addChild(viewComponent);
			(facade.retrieveProxy( ClassesProxy.NAME ) as ClassesProxy).addClass(viewComponent);
			
			//cRUDdyBuddyMediator.cruddyBuddy.tabsArray.push(viewComponent);

		}
		
	}
}